/*
 * @Author: zqx me_zqx@163.com
 * @Date: 2025-07-11 20:01:53
 * @LastEditors: zqx me_zqx@163.com
 * @LastEditTime: 2025-09-15 18:41:54
 * @FilePath: /XMate-h5/src/utils/auth.js
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
 */
import { isInIframe } from "@/utils/platformTool";
const TokenKey = "fast-token";
const TokenPrefix = "Bearer ";
const UserInfoKey_PC = "yxtlm_userInfo";
const EnvKey = "yxt-env";

const getToken = () => {
  return localStorage.getItem(TokenKey) || JSON.parse(localStorage.getItem(UserInfoKey_PC)).token;
};

const setToken = token => {
  localStorage.setItem(TokenKey, token);
};
const clearToken = () => {
  localStorage.removeItem(TokenKey);
};

const getShareToken = () => {
  return sessionStorage.getItem("shareToken");
};
const setShareToken = token => {
  sessionStorage.setItem("shareToken", token);
};

const getUserInfo = () => {
  const userInfo = localStorage.getItem("yxt-userInfo");
  return JSON.parse(userInfo) || {};
};

const setUserInfo = userInfo => {
  localStorage.setItem("yxt-userInfo", JSON.stringify(userInfo));
};

export {
  TokenPrefix,
  getToken,
  setToken,
  clearToken,
  getUserInfo,
  setUserInfo,
  getShareToken,
  setShareToken,
  isInIframe,
};
